#ifndef SERIALDRIVER_H
#define SERIALDRIVER_H

#include <Globals.h>
#include <MonitorDriver.h>

#define SERIAL_COM1  0x3f8

class SerialDriver
{
public:

  SerialDriver(u16int port=SERIAL_COM1);

  ~SerialDriver();

  void init() 
  {
  }
  
    
  /**
    Writes a string out to the serial port
  **/
  void write(char *c, Colour foreColour=none, Colour backColour=none);
  void write(const char *c, Colour foreColour=none, Colour backColour=none)
  {
    write((char*)c, foreColour, backColour);
  }
  
  /**
    Writes a 32-bit signed integer as a hexadecimal number to the serial port
  **/
  void writeHex(s32int n, Colour foreColour=none, Colour backColour=none);

  /**
    Writes a 32-bit signed integer as a decimal number to the serial port
  **/
  void writeDec(s32int n, Colour foreColour=none, Colour backColour=none);

  /**
    Puts a character out to the serial port
  **/
  void put(char c, Colour foreColour=none, Colour backColour=none);
  
  /**
    Overloads << to print nicely.
  **/
  SerialDriver &operator<<(char *c);
  SerialDriver &operator<<(const char *c);
  SerialDriver &operator<<(u32int i);
  SerialDriver &operator<<(Special s);

private:

  /**
    Returns true if the port's transmit buffer is empty.
  **/
  bool readyToTransmit();
  
  
  /**
    The base register address of our port
  **/
  u16int port;
  
  /**
    Decimal or hex mode
  **/
  Special intMode;

  /**
    Outputs colour codes for vt100 consoles.
  **/
  void startColour(Colour foreColour, Colour backColour);
  void endColour();

};

#endif
